﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.DataLayer;


namespace XJX.BusinessLayer
{
    public class Exchange
    {
        private string ConnToData;

        public Exchange(string newConnectionString)
        {
            ConnToData = newConnectionString;
        }

        public bool Add_New_ExchangeTheme
            (
            string Title,
            string Content,
            string UID,
            out int ReturnValue,          //返回参数值
            out string ReturnFieldValue   //返回字段值,返回插入的新值ID编号
            )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Exchange(ConnToData).Add_New_ExchangeTheme(Title, Content, UID, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        public bool Del_One_ExchangeTheme_From_EXID(string EXID,string UID)
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Exchange(ConnToData).Del_One_ExchangeTheme_From_EXID(EXID,UID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        public bool Modify_One_ExchangeTheme_Info
            (
            string EXID,
            string UID,
            string Title,
            string Content
            )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Exchange(ConnToData).Modify_One_ExchangeTheme_Info(EXID,UID,Title,Content);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //得到一个交流主题的内容
        public Hashtable Get_One_ExchangeTheme_Info_From_EXID(string EXID)
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();

            DataSet ds = new XJX.DataLayer.Exchange(ConnToData).Get_One_ExchangeTheme_Info_From_EXID(EXID);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["rows"] = data;

            return ht;
        }

        //得到某个家庭发表的所有交流主题标题列表
        public Hashtable Get_One_Family_All_ExchangeTheme_List
            (
            string UID,
            string Title,

            int PageIndex,
            int PageSize
            )
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;


            DataSet ds = new XJX.DataLayer.Exchange(ConnToData).Get_One_Family_All_ExchangeTheme_List
                    (UID,Title, "One_Family_All_ExchangeTheme", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }


        //一般浏览用户或者管理员获取交流主题的标题列表
        public Hashtable Get_ExchangeTheme_List
            (
            string Title,
            string IsAll,

            int PageIndex,
            int PageSize
            )
        {
            Hashtable ht = new Hashtable();
            DataTable dt = new DataTable();
            int PageCount = 0;
            int TotalCount = 0;


            DataSet ds = new XJX.DataLayer.Exchange(ConnToData).Get_ExchangeTheme_List
                    (Title,IsAll, "All_Exchangetheme_List", PageIndex, PageSize, out PageCount, out TotalCount);
            dt = ds.Tables[0];

            ArrayList data = Common.DataTable2ArrayList(dt);

            ht["PageCount"] = PageCount;//页数,将在哈希表中输出成字符串。
            ht["RecordCount"] = TotalCount;//记录总数
            ht["rows"] = data;

            return ht;
        }

        //屏蔽或显示一条交流主题
        public bool ShieldORDisp_One_ExchangeTheme_By_EXID
        (
            string EXID,
            out int ReturnValue,
            out string ReturnFieldValue
            )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Exchange(ConnToData).ShieldORDisp_One_ExchangeTheme_By_EXID(EXID, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }


        //置顶一条交流主题
        public bool StickORCannel_One_ExchangeTheme_By_EXID
        (
            string EXID,
            out int ReturnValue,
            out string ReturnFieldValue
            )
        {
            bool b;

            try
            {
                b = new XJX.DataLayer.Exchange(ConnToData).StickORCannel_One_ExchangeTheme_By_EXID(EXID, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

    }
}
